#	m42-xmas-memory
#   Copyright (C) 2014  Jannik Haberbosch
#
#	This program is free software: you can redistribute it and/or modify
#	it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.


import pygame
pygame.init()

from code.constants import colours


class Card( pygame.sprite.Sprite ):
	"""Represents a single memory card.

	"""
	def __init__( self, row, col, picture_with_id, size ):
		pygame.sprite.Sprite.__init__( self )

		self.row = row
		self.col = col
		self.id = picture_with_id[0]
		self.picture = picture_with_id[1]

		self.overlay = pygame.Surface( ( size, size ) )
		self.overlay.fill( ( colours.GREY ) )
		
		self.image = self.overlay
		self.rect = self.image.get_rect( topleft = ( col * size + 5 * col , row * size + 5 * row ) )

		self.flipped = False


	def update( self ):
		if self.rect.collidepoint( pygame.mouse.get_pos() ) and not self.flipped:
			if pygame.mouse.get_pressed()[0]:
				self.image = self.picture
				self.flipped = True
				return True

		return False
